<template>
  <div>
    <div>
      <div class="policy-title-text">政策信息</div>
      <el-row :gutter="20">
        <el-form
          :model="policyForm"
          :rules="policyRules"
          ref="policyForm"
          label-width="120px"
        >
          <el-col :span="6">
            <el-form-item label="政策名称:" prop="polName">
              <el-input
                size="small"
                v-model="policyForm.polName"
                placeholder="请输入政策名称"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="政策类型:" prop="polType">
              <el-select
                size="small"
                v-model="policyForm.polType"
                placeholder="请选择政策类型"
              >
                <el-option
                  :label="item.dictValue"
                  :value="item.dictKey"
                  v-for="(item, index) in polTypeList"
                  :key="index"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="政策类别:" prop="polCategory">
              <el-select
                size="small"
                v-model="policyForm.polCategory"
                placeholder="请选择政策类别"
              >
                <el-option
                  :label="item.dictValue"
                  :value="item.dictKey"
                  v-for="(item, index) in polCategoryList"
                  :key="index"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="政策分类:" prop="polKind">
              <el-select
                size="small"
                v-model="policyForm.polKind"
                placeholder="请选择政策分类"
              >
                <el-option
                  :label="item.dictValue"
                  :value="item.dictKey"
                  v-for="(item, index) in polKindList"
                  :key="index"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
    </div>
    <div>
      <div class="policy-title-text">分润配置</div>
    </div>
    <div
      class="
        haruyuki-width-100
        haruyuki-flex-space-between
        haruyuki-align-items-center
        haruyuki-mb-20
      "
    >
      <div>
        <span class="haruyuki-size-14">选择通道：</span>
        <el-select
          size="small"
          v-model="aisleData"
          @change="templateAllChange"
          placeholder="请选择通道"
        >
          <el-option
            v-for="item in aisleList"
            :key="item.aisleCode"
            :label="item.aisleName"
            :value="item.aisleCode"
          >
          </el-option>
        </el-select>
      </div>
      <div class="haruyuki-flex-center">
        <div class="haruyuki-mr-20">
          <span>成本费率：</span>
          <el-input-number
            size="mini"
            v-model="aptTemplate.aptRate"
            :precision="4"
            :step="0.0001"
            :min="0"
            :max="1"
          ></el-input-number>
          <span> %</span>
        </div>
        <div class="haruyuki-mr-20">
          <span>结算比例：</span>
          <el-input-number
            size="mini"
            v-model="aptTemplate.aptScale"
            :precision="0"
            :min="1"
            :max="100"
          ></el-input-number>
          <span> %</span>
        </div>
        <div class="haruyuki-mr-20">
          <span>最低金额：</span>
          <el-input-number
            size="mini"
            v-model="aptTemplate.aptMin"
            :precision="2"
            :step="0.1"
            :min="0"
          ></el-input-number>
          <span> ¥</span>
        </div>
        <el-button type="primary" size="small" plain @click="submitCover"
          >一键填入</el-button
        >
      </div>
    </div>
    <div class="haruyuki-scrollbar-60vh haruyuki-p-10">
      <div
        class="aisle-policy-box haruyuki-mb-20"
        v-for="(dataItem, index) in data"
        :key="index"
      >
        <div
          class="
            haruyuki-width-100
            haruyuki-flex-space-between
            haruyuki-align-items-center
            aisle-policy-bg
          "
        >
          <div>
            <span
              class="haruyuki-size-16 policy-ml-3 policy-mr-3"
              @click="dataItem.isShow = !dataItem.isShow"
              ><i
                :class="
                  dataItem.isShow
                    ? 'el-icon-caret-bottom'
                    : 'el-icon-caret-right'
                "
              ></i
              >通道名称：{{ dataItem.aisleName }}</span
            >
          </div>
          <div class="haruyuki-flex-center">
            <div class="haruyuki-mr-20">
              <span>成本费率：</span>
              <el-input-number
                size="mini"
                v-model="dataItem.aptRate"
                :precision="4"
                :step="0.0001"
                :min="0"
                :max="1"
              ></el-input-number>
              <span> %</span>
            </div>
            <div class="haruyuki-mr-20">
              <span>结算比例：</span>
              <el-input-number
                size="mini"
                v-model="dataItem.aptScale"
                :precision="0"
                :min="1"
                :max="100"
              ></el-input-number>
              <span> %</span>
            </div>
            <div class="haruyuki-mr-20">
              <span>最低金额：</span>
              <el-input-number
                size="mini"
                v-model="dataItem.aptMin"
                :precision="2"
                :step="0.1"
                :min="0"
              ></el-input-number>
              <span> ¥</span>
            </div>
            <div class="policy-mr-3">
              <el-button
                type="primary"
                size="mini"
                plain
                @click.stop="submitChildCover(dataItem, index)"
                >一键填入</el-button
              >
            </div>
          </div>
          <div class="policy-mr-3">
            <el-button
              type="danger"
              size="mini"
              plain
              @click.stop="policyDelete(index)"
              >删除</el-button
            >
          </div>
        </div>
        <div
          class="custom-tree-container"
          v-show="dataItem.isShow"
          v-for="(interItem, interIndex) in dataItem.intervalList"
          :key="interItem.id"
        >
          <div
            class="
              haruyuki-line-height-special
              haruyuki-flex
              haruyuki-align-items-center
              haruyuki-plr-20
            "
          >
            <div @click="interItem.isShow = !interItem.isShow">
              <i
                :class="
                  interItem.isShow
                    ? 'el-icon-caret-bottom'
                    : 'el-icon-caret-right'
                "
              ></i
              >阶梯{{ interIndex + 1 }}：
            </div>
            <div class="haruyuki-flex haruyuki-align-items-center">
              范围区间：<el-input-number
                size="mini"
                v-model="interItem.aptStartMoney"
                :precision="2"
                :step="0.1"
                :min="0"
              ></el-input-number
              ><span>~</span
              ><el-input-number
                size="mini"
                v-model="interItem.aptEndMoney"
                :precision="2"
                :step="0.1"
                :min="0.1"
              ></el-input-number>
              <div
                class="policy-ml-3 policy-mr-3"
                v-if="interItem.id == dataItem.stateIndex"
              >
                <el-button
                  type="text"
                  size="mini"
                  @click="() => ladderAppend(interItem, interIndex, index)"
                >
                  新增
                </el-button>
              </div>
              <div
                class="policy-ml-3"
                v-if="interItem.id == dataItem.stateIndex && interIndex != 0"
              >
                <el-button
                  type="text"
                  size="mini"
                  @click="() => ladderRemove(interIndex, index)"
                >
                  删除
                </el-button>
              </div>
            </div>
          </div>
          <div v-show="interItem.isShow">
            <div class="haruyuki-line-height-special haruyuki-plr-40">
              <span>扫码垫资费费率：</span>
              <el-input-number
                size="mini"
                v-model="interItem.codeAdvanceRate"
                :precision="4"
                :step="0.0001"
                :min="0"
                :max="1"
              ></el-input-number>
              <span> %</span>
            </div>
            <div class="haruyuki-line-height-special haruyuki-plr-40">
              <span>扫码垫资费费率最低值：</span>
              <el-input-number
                size="mini"
                v-model="interItem.codeAdvanceMin"
                :precision="2"
                :min="0"
                :max="9999999"
              ></el-input-number>
              <span> ¥</span>
            </div>
            <!-- START 扫码 -->
            <div
              class=""
              v-for="productItem in interItem.productList"
              :key="productItem.id"
            >
              <div
                class="haruyuki-line-height-special haruyuki-plr-40"
                @click="productItem.isShow = !productItem.isShow"
              >
                <i
                  :class="
                    productItem.isShow
                      ? 'el-icon-caret-bottom'
                      : 'el-icon-caret-right'
                  "
                ></i>
                <span>{{ productItem.compName }}：</span>
              </div>
              <div v-if="productItem.isSingleInterval == 0">
                <div
                  v-show="productItem.isShow"
                  v-for="(
                    singleItem, singleIndex
                  ) in productItem.singlePayInterval"
                  :key="singleIndex"
                >
                  <div class="haruyuki-line-height-special haruyuki-plr-60">
                    <span>成本费率：</span>
                    <el-input-number
                      size="mini"
                      v-model="singleItem.aptRate"
                      :precision="4"
                      :step="0.0001"
                      :min="0"
                      :max="1"
                    ></el-input-number>
                    <span> %</span>
                  </div>
                  <div class="haruyuki-line-height-special haruyuki-plr-60">
                    <span>结算比例：</span>
                    <el-input-number
                      size="mini"
                      v-model="singleItem.aptScale"
                      :precision="0"
                      :min="1"
                      :max="100"
                    ></el-input-number>
                    <span> %</span>
                  </div>
                  <div class="haruyuki-line-height-special haruyuki-plr-60">
                    <span>最低金额：</span>
                    <el-input-number
                      size="mini"
                      v-model="singleItem.aptMin"
                      :precision="2"
                      :step="0.1"
                      :min="0"
                    ></el-input-number>
                    <span> ¥</span>
                  </div>
                </div>
              </div>

              <div v-if="productItem.isSingleInterval == 1">
                <div v-show="productItem.isShow">
                  <div class="haruyuki-line-height-special haruyuki-plr-60">
                    <span>交易金额小于 </span>
                    <el-input-number
                      size="mini"
                      :disabled="true"
                      v-model="productItem.intervalMoney"
                      :precision="2"
                      :min="0"
                    ></el-input-number>
                    <span> 时</span>
                  </div>
                  <div class="haruyuki-line-height-special haruyuki-plr-80">
                    <span>借记卡成本费率：</span>
                    <el-input-number
                      size="mini"
                      v-model="productItem.singlePayInterval[0].aptRate"
                      :precision="4"
                      :step="0.0001"
                      :min="0"
                      :max="1"
                    ></el-input-number>
                    <span> %</span>
                  </div>
                  <div class="haruyuki-line-height-special haruyuki-plr-80">
                    <span>借记卡结算比例：</span>
                    <el-input-number
                      size="mini"
                      v-model="productItem.singlePayInterval[0].aptScale"
                      :precision="0"
                      :min="1"
                      :max="100"
                    ></el-input-number>
                    <span> %</span>
                  </div>
                  <div class="haruyuki-line-height-special haruyuki-plr-80">
                    <span>借记卡最低金额：</span>
                    <el-input-number
                      size="mini"
                      v-model="productItem.singlePayInterval[0].aptMin"
                      :precision="2"
                      :step="0.1"
                      :min="0"
                    ></el-input-number>
                    <span> ¥</span>
                  </div>
                  <div class="haruyuki-line-height-special haruyuki-plr-80">
                    <span>借记卡封顶金额：</span>
                    <el-input-number
                      size="mini"
                      v-model="productItem.singlePayInterval[0].aptMax"
                      :precision="2"
                      :step="0.1"
                      :min="0"
                    ></el-input-number>
                    <span> ¥</span>
                  </div>

                  <div class="haruyuki-line-height-special haruyuki-plr-80">
                    <span>贷记卡成本费率：</span>
                    <el-input-number
                      size="mini"
                      v-model="productItem.singlePayInterval[0].creditAptRate"
                      :precision="4"
                      :step="0.0001"
                      :min="0"
                      :max="1"
                    ></el-input-number>
                    <span> %</span>
                  </div>
                  <div class="haruyuki-line-height-special haruyuki-plr-80">
                    <span>贷记卡结算比例：</span>
                    <el-input-number
                      size="mini"
                      v-model="productItem.singlePayInterval[0].creditAptScale"
                      :precision="0"
                      :min="1"
                      :max="100"
                    ></el-input-number>
                    <span> %</span>
                  </div>
                  <div class="haruyuki-line-height-special haruyuki-plr-80">
                    <span>贷记卡最低金额：</span>
                    <el-input-number
                      size="mini"
                      v-model="productItem.singlePayInterval[0].creditAptMin"
                      :precision="2"
                      :step="0.1"
                      :min="0"
                    ></el-input-number>
                    <span> ¥</span>
                  </div>

                  <div class="haruyuki-line-height-special haruyuki-plr-60">
                    <span>交易金额大于 </span>
                    <el-input-number
                      size="mini"
                      :disabled="true"
                      v-model="productItem.intervalMoney"
                      :precision="2"
                      :min="0"
                    ></el-input-number>
                    <span> 时</span>
                  </div>
                  <div class="haruyuki-line-height-special haruyuki-plr-80">
                    <span>借记卡成本费率：</span>
                    <el-input-number
                      size="mini"
                      v-model="productItem.singlePayInterval[1].aptRate"
                      :precision="4"
                      :step="0.0001"
                      :min="0"
                      :max="1"
                    ></el-input-number>
                    <span> %</span>
                  </div>
                  <div class="haruyuki-line-height-special haruyuki-plr-80">
                    <span>借记卡结算比例：</span>
                    <el-input-number
                      size="mini"
                      v-model="productItem.singlePayInterval[1].aptScale"
                      :precision="0"
                      :min="1"
                      :max="100"
                    ></el-input-number>
                    <span> %</span>
                  </div>
                  <div class="haruyuki-line-height-special haruyuki-plr-80">
                    <span>借记卡最低金额：</span>
                    <el-input-number
                      size="mini"
                      v-model="productItem.singlePayInterval[1].aptMin"
                      :precision="2"
                      :step="0.1"
                      :min="0"
                    ></el-input-number>
                    <span> ¥</span>
                  </div>
                  <div class="haruyuki-line-height-special haruyuki-plr-80">
                    <span>借记卡封顶金额：</span>
                    <el-input-number
                      size="mini"
                      v-model="productItem.singlePayInterval[1].aptMax"
                      :precision="2"
                      :step="0.1"
                      :min="0"
                    ></el-input-number>
                    <span> ¥</span>
                  </div>

                  <div class="haruyuki-line-height-special haruyuki-plr-80">
                    <span>贷记卡成本费率：</span>
                    <el-input-number
                      size="mini"
                      v-model="productItem.singlePayInterval[1].creditAptRate"
                      :precision="4"
                      :step="0.0001"
                      :min="0"
                      :max="1"
                    ></el-input-number>
                    <span> %</span>
                  </div>
                  <div class="haruyuki-line-height-special haruyuki-plr-80">
                    <span>贷记卡结算比例：</span>
                    <el-input-number
                      size="mini"
                      v-model="productItem.singlePayInterval[1].creditAptScale"
                      :precision="0"
                      :min="1"
                      :max="100"
                    ></el-input-number>
                    <span> %</span>
                  </div>
                  <div class="haruyuki-line-height-special haruyuki-plr-80">
                    <span>贷记卡最低金额：</span>
                    <el-input-number
                      size="mini"
                      v-model="productItem.singlePayInterval[1].creditAptMin"
                      :precision="2"
                      :step="0.1"
                      :min="0"
                    ></el-input-number>
                    <span> ¥</span>
                  </div>
                </div>
              </div>
            </div>
            <!-- END 扫码 -->
            <!-- START 刷卡 -->
            <div
              class="haruyuki-line-height-special haruyuki-plr-40"
              @click.stop="interItem.posTrad.isShow = !interItem.posTrad.isShow"
            >
              <i
                :class="
                  interItem.posTrad.isShow
                    ? 'el-icon-caret-bottom'
                    : 'el-icon-caret-right'
                "
              ></i>
              <span>刷卡：</span>
            </div>
            <div
              v-show="interItem.posTrad.isShow"
            >
              <div class="haruyuki-line-height-special haruyuki-plr-60">
                <span>贷记卡费率：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.creditRate"
                  :precision="4"
                  :step="0.0001"
                  :min="0"
                  :max="1"
                ></el-input-number>
                <span> %</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60">
                <span>贷记卡费率封底：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.creditRateMin"
                  :precision="2"
                  :step="0.1"
                  :min="0"
                ></el-input-number>
                <span> ¥</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60">
                <span>贷记卡结算比例：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.creditScale"
                  :precision="0"
                  :min="1"
                  :max="100"
                ></el-input-number>
                <span> %</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60">
                <span>贷记卡垫资费率：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.creditCodeAdvanceRate"
                  :precision="4"
                  :step="0.0001"
                  :min="0"
                  :max="1"
                ></el-input-number>
                <span> %</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60">
                <span>贷记卡垫资费率封顶：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.creditCodeAdvanceRateMax"
                  :precision="2"
                  :step="0.1"
                  :min="0"
                ></el-input-number>
                <span> ¥</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60">
                <span>贷记卡垫资费率封底：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.creditCodeAdvanceRateMin"
                  :precision="2"
                  :step="0.1"
                  :min="0"
                ></el-input-number>
                <span> ¥</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60">
                <span>借记卡费率：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.debtRate"
                  :precision="4"
                  :step="0.0001"
                  :min="0"
                  :max="1"
                ></el-input-number>
                <span> %</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60">
                <span>借记卡费率封顶：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.debtRateMax"
                  :precision="2"
                  :step="0.1"
                  :min="0"
                ></el-input-number>
                <span> ¥</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60">
                <span>借记卡费率封底：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.debtRateMin"
                  :precision="2"
                  :step="0.1"
                  :min="0"
                ></el-input-number>
                <span> ¥</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60">
                <span>借记卡结算比例：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.debtScale"
                  :precision="0"
                  :min="1"
                  :max="100"
                ></el-input-number>
                <span> %</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60">
                <span>借记卡垫资费率：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.debtCodeAdvanceRate"
                  :precision="4"
                  :step="0.0001"
                  :min="0"
                  :max="1"
                ></el-input-number>
                <span> %</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60">
                <span>借记卡垫资费率封顶：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.debtCodeAdvanceRateMax"
                  :precision="2"
                  :step="0.1"
                  :min="0"
                ></el-input-number>
                <span> ¥</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60">
                <span>借记卡垫资费率封底：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.debtCodeAdvanceRateMin"
                  :precision="2"
                  :step="0.1"
                  :min="0"
                ></el-input-number>
                <span> ¥</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60">
                <span>挥卡费率：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.waveRate"
                  :precision="4"
                  :step="0.0001"
                  :min="0"
                  :max="1"
                ></el-input-number>
                <span> %</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60">
                <span>挥卡结算比例：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.waveScale"
                  :precision="0"
                  :min="1"
                  :max="100"
                ></el-input-number>
                <span> %</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60" v-if="interItem.posTrad.isShowVip == 1">
                <span>银联费率：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.unionpayRate"
                  :precision="4"
                  :step="0.0001"
                  :min="0"
                  :max="1"
                ></el-input-number>
                <span> %</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60" v-if="interItem.posTrad.isShowVip == 1">
                <span>银联结算比例：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.unionpayScale"
                  :precision="0"
                  :min="1"
                  :max="100"
                ></el-input-number>
                <span> %</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60" v-if="interItem.posTrad.isShowVip == 1">
                <span>尊享费率：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.vipRate"
                  :precision="4"
                  :step="0.0001"
                  :min="0"
                  :max="1"
                ></el-input-number>
                <span> %</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60" v-if="interItem.posTrad.isShowVip == 1">
                <span>尊享结算比例：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.vipScale"
                  :precision="0"
                  :min="1"
                  :max="100"
                ></el-input-number>
                <span> %</span>
              </div>
            </div>
            <!-- END 刷卡 -->
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getDictionary } from "@/api/system/dict";
import {
  getAisleList,
  getAisleDetail,
} from "@/api/rb-core/oempolicy/oem_policy";
let intId = 1;
let pid = 1000;
export default {
  props: {
    policyForm: Object,
    oem: Object,
  },
  data() {
    return {
      policyRules: {
        polName: [
          { required: true, message: "请输入政策名称", trigger: "blur" },
        ],
        polType: [
          { required: true, message: "请选择政策类型", trigger: "blur" },
        ],
        polCategory: [
          { required: true, message: "请选择政策类别", trigger: "blur" },
        ],
        polKind: [
          { required: true, message: "请选择政策分类", trigger: "blur" },
        ],
      },
      polTypeList: [],
      polCategoryList: [],
      polKindList: [],
      initData: [],
      data: [], //通道政策 树形数据
      aisleList: [],
      aisleData: null,
      aptTemplate: {
        aptRate: -1,
        aptScale: -1,
        aptMin: -1,
      },
    };
  },
  watch: {
    data: {
      deep: true,
      handler(val) {
        if (val) {
          for (let i = 0; i < val.length; i++) {
            val[i].stateIndex =
              val[i].intervalList[val[i].intervalList.length - 1].id;
          }
        }
      },
    },
  },
  created() {
    this.data = [];
    this.doGetDicts();
    this.getAisleSelect();
  },
  methods: {
    /* 字典 */
    doGetDicts() {
      getDictionary({ code: "pol_type" }).then((res) => {
        this.polTypeList = res.data.data;
      });
      getDictionary({ code: "pol_category" }).then((res) => {
        this.polCategoryList = res.data.data;
      });
      getDictionary({ code: "pol_kind" }).then((res) => {
        this.polKindList = res.data.data;
      });
    },
    /* 通道列表 */
    getAisleSelect() {
      getAisleList("-1", "-1").then((res) => {
        this.aisleList = res.data.data.records;
      });
    },
    /* 选中通道 渲染政策模板 */
    templateAllChange(e) {
      this.$confirm("是否为该通道新增模板?", "新增模板", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
      })
        .then(() => {
          if (this.data.length > 0) {
            for (const item of this.data) {
              if (e === item.aisleCode) {
                this.$message({
                  type: "warning",
                  message: "无法重复新增此通道为模板！",
                });
                return false;
              }
            }
          }

          getAisleDetail(e).then((res) => {
            if (res.data.code == "200") {
              this.initData.push(res.data.data);
              for (let i = 0; i < this.initData.length; i++) {
                this.$set(this.initData[i], "isShow", true);
                this.$set(this.initData[i], "aptMin", -1);
                this.$set(this.initData[i], "aptRate", -1);
                this.$set(this.initData[i], "aptScale", -1);
                this.$set(this.initData[i], "stateIndex", -1);
                for (let j = 0; j < this.initData[i].intervalList.length; j++) {
                  this.$set(this.initData[i].intervalList[j], "isShow", true);
                  this.$set(this.initData[i].intervalList[j], "id", intId++);
                  this.$set(this.initData[i].intervalList[j].posTrad, "isShow", true);
                  for (let k = 0; k < this.initData[i].intervalList[j].productList.length; k++) {
                    this.$set(
                      this.initData[i].intervalList[j].productList[k],
                      "isShow",
                      true
                    );
                    this.$set(
                      this.initData[i].intervalList[j].productList[k],
                      "id",
                      pid++
                    );
                  }
                }
              }
              this.$nextTick(() => {
                this.data = JSON.parse(JSON.stringify(this.initData));
                // console.log(this.data, 'temp---data')
              });
              this.$message({
                type: "success",
                message: "新增成功!",
              });
            } else {
              this.$message({
                type: "error",
                message: res.data.message,
              });
            }
          });
        })
        .catch(() => {
          this.aisleData = null;
          // this.$message({
          //   type: "info",
          //   message: "已取消",
          // });
        });
    },
    getEditDatail(data) {
      this.initData = data.aisleList;
      for (let i = 0; i < this.initData.length; i++) {
        this.$set(this.initData[i], "isShow", true);
        this.$set(this.initData[i], "aptMin", -1);
        this.$set(this.initData[i], "aptRate", -1);
        this.$set(this.initData[i], "aptScale", -1);
        this.$set(this.initData[i], "stateIndex", -1);
        for (let j = 0; j < this.initData[i].intervalList.length; j++) {
          this.$set(this.initData[i].intervalList[j], "isShow", true);
          this.$set(this.initData[i].intervalList[j], "id", intId++);
          this.$set(this.initData[i].intervalList[j].posTrad, "isShow", true);
          for (let k = 0; k < this.initData[i].intervalList[j].productList.length; k++) {
            this.$set(
              this.initData[i].intervalList[j].productList[k],
              "isShow",
              true
            );
            this.$set(
              this.initData[i].intervalList[j].productList[k],
              "id",
              pid++
            );
          }
        }
      }

      this.$nextTick(() => {
        this.data = JSON.parse(JSON.stringify(this.initData));
      });
    },
    /* 删除对应的通道政策 */
    policyDelete(i) {
      this.$confirm("是否删除该通道政策模板?", "删除", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
      })
        .then(() => {
          this.data.splice(i, 1);
          this.initData.splice(i, 1);
          this.aisleData = null;
          -this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          // this.$message({
          //   type: "info",
          //   message: "已取消",
          // });
        });
    },
    /* 全通道政策模板 一键填入 */
    submitCover() {
      if (this.aptTemplate.aptRate == 0) {
        this.$message({
          type: "warning",
          message: "请输入成本费率",
        });
      } else if (this.aptTemplate.aptScale == 0) {
        this.$message({
          type: "warning",
          message: "请输入结算比例",
        });
      } else if (this.aptTemplate.aptMin == 0) {
        this.$message({
          type: "warning",
          message: "请输入最低金额",
        });
      } else {
        for (let d = 0; d < this.data.length; d++) {
          for (let i = 0; i < this.data[d].intervalList.length; i++) {
            this.data[d].intervalList[i].posTrad.aptScale = this.aptTemplate.aptScale;
            this.data[d].intervalList[i].posTrad.aptMin = this.aptTemplate.aptMin;
            for (
              let p = 0;
              p < this.data[d].intervalList[i].productList.length;
              p++
            ) {
              if (
                this.data[d].intervalList[i].productList[p].isSingleInterval ==
                0
              ) {
                for (
                  let s = 0;
                  s <
                  this.data[d].intervalList[i].productList[p].singlePayInterval
                    .length;
                  s++
                ) {
                  this.data[d].intervalList[i].productList[p].singlePayInterval[
                    s
                  ].aptRate = this.aptTemplate.aptRate;
                  this.data[d].intervalList[i].productList[p].singlePayInterval[
                    s
                  ].aptScale = this.aptTemplate.aptScale;
                  this.data[d].intervalList[i].productList[p].singlePayInterval[
                    s
                  ].aptMin = this.aptTemplate.aptMin;
                }
              } else if (this.data[d].intervalList[i].productList[p].isSingleInterval == 1) {
                for ( let s = 0; s < this.data[d].intervalList[i].productList[p].singlePayInterval.length; s++ ) {
                  this.data[d].intervalList[i].productList[p].singlePayInterval[s].aptRate = this.aptTemplate.aptRate;
                  this.data[d].intervalList[i].productList[p].singlePayInterval[s].creditAptRate = this.aptTemplate.aptRate;
                  this.data[d].intervalList[i].productList[p].singlePayInterval[s].aptScale = this.aptTemplate.aptScale;
                  this.data[d].intervalList[i].productList[p].singlePayInterval[s].creditAptScale = this.aptTemplate.aptScale;
                  this.data[d].intervalList[i].productList[p].singlePayInterval[s].aptMin = this.aptTemplate.aptMin;
                  this.data[d].intervalList[i].productList[p].singlePayInterval[s].creditAptMin = this.aptTemplate.aptMin;
                }
              }
            }
          }
        }
      }
    },
    /* 单通道政策模板 一键填入 */
    submitChildCover(data, index) {
      if (data.aptRate == 0) {
        this.$message({
          type: "warning",
          message: "请输入成本费率",
        });
      } else if (data.aptScale == 0) {
        this.$message({
          type: "warning",
          message: "请输入结算比例",
        });
      } else if (data.aptMin == 0) {
        this.$message({
          type: "warning",
          message: "请输入最低金额",
        });
      } else {
        for (let i = 0; i < data.intervalList.length; i++) {
          data.intervalList[i].posTrad.aptScale = data.aptScale;
          data.intervalList[i].posTrad.aptMin = data.aptMin;
          for (let p = 0; p < data.intervalList[i].productList.length; p++) {
            if (data.intervalList[i].productList[p].isSingleInterval == 0) {
              for (
                let s = 0;
                s <
                data.intervalList[i].productList[p].singlePayInterval.length;
                s++
              ) {
                data.intervalList[i].productList[p].singlePayInterval[
                  s
                ].aptRate = data.aptRate;
                data.intervalList[i].productList[p].singlePayInterval[
                  s
                ].aptScale = data.aptScale;
                data.intervalList[i].productList[p].singlePayInterval[
                  s
                ].aptMin = data.aptMin;
              }
            } else if (data.intervalList[i].productList[p].isSingleInterval == 1) {
              for ( let s = 0; s < data.intervalList[i].productList[p].singlePayInterval.length; s++ ) {
                data.intervalList[i].productList[p].singlePayInterval[s].aptRate = data.aptRate;
                data.intervalList[i].productList[p].singlePayInterval[s].creditAptRate = data.aptRate;
                data.intervalList[i].productList[p].singlePayInterval[s].aptScale = data.aptScale;
                data.intervalList[i].productList[p].singlePayInterval[s].creditAptScale = data.aptScale;
                data.intervalList[i].productList[p].singlePayInterval[s].aptMin = data.aptMin;
                data.intervalList[i].productList[p].singlePayInterval[s].creditAptMin = data.aptMin;
              }
            }
          }
        }
      }
    },
    /* 新增阶梯 */
    ladderAppend(interData, interIndex, index) {
      let intData = JSON.parse(JSON.stringify(interData));
      intData.id = intId++;
      intData.aptStartMoney = intData.aptEndMoney;
      intData.aptEndMoney = intData.aptEndMoney + 1;
      intData.codeAdvanceRate = 0; //初始化 扫码垫资费费率
      intData.codeAdvanceMin = 0; //初始化 扫码垫资费费率最低值
      intData.aptGrade = intData.id; //阶段层级赋值

      // 刷卡 赋空值
      Object.keys(intData.posTrad).forEach(key=>{
        if (key !== 'isShow') {
          intData.posTrad[key] = 0;
        }
      })

      // 扫码 赋空值
      for (let j = 0; j < interData.productList.length; j++) {
        intData.productList[j].id = pid++;
        for (
          let k = 0;
          k < interData.productList[j].singlePayInterval.length;
          k++
        ) {
          intData.productList[j].singlePayInterval[k].aptMin = 0;
          intData.productList[j].singlePayInterval[k].aptRate = 0;
          intData.productList[j].singlePayInterval[k].aptScale = 0;
          intData.productList[j].singlePayInterval[k].creditAptMin = 0;
          intData.productList[j].singlePayInterval[k].creditAptRate = 0;
          intData.productList[j].singlePayInterval[k].creditAptScale = 0;
        }
      }
      this.initData[index].intervalList.push(intData);
      this.data[index].intervalList.push(intData);
    },
    /* 删除阶梯 */
    ladderRemove(interIndex, index) {
      this.initData[index].intervalList.splice(interIndex, 1);
      this.data[index].intervalList.splice(interIndex, 1);
    },
  },
};
</script>

<style lang="scss" scoped>
.policy-title-text {
  font-size: 22px;
  margin-bottom: 14px;
}

/deep/.el-tree-node__content {
  height: 40px;
  line-height: 40px;
  // background: #eeeeee;
  // border: 1px solid #eeeeee;
}

.aisle-policy-box {
  border: 1px solid #e0eafc;
  box-shadow: 0 2px 12px rgba(224, 234, 252, 0.8);
}
.aisle-policy-bg {
  background-color: #e0eafc;
  padding: 10px 0;
}

.policy-mr-3 {
  margin-right: 3px;
}
.policy-ml-3 {
  margin-left: 3px;
}
</style>
